package com.phpxiu.app.adapter.holder;

import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.gift.Gift;
import com.phpxiu.app.view.custom.FrescoImageView;
import com.phpxiu.app.view.custom.VerticalImageSpan;

/**
 * Created by WuJinZhou on 2016/5/25.
 */
public class RoomGiftViewHolder {
    private final static String END_STR=" icon_str";
    private SpannableStringBuilder txt=new SpannableStringBuilder();
    private VerticalImageSpan mSpan;
    private Gift gift;
    public LinearLayout mItemView;
    public FrescoImageView icon;
    public ImageView checkIcon;
    public TextView price;
    public TextView description;
    public RoomGiftViewHolder(View itemView,VerticalImageSpan span) {
        mSpan=span;
        mItemView=(LinearLayout)itemView.findViewById(R.id.main_room_window_gift_grid_item_view);
        icon=(FrescoImageView)itemView.findViewById(R.id.gift_icon_view);
        checkIcon=(ImageView)itemView.findViewById(R.id.check_icon_view);
        price=(TextView)itemView.findViewById(R.id.gift_price);
        description=(TextView)itemView.findViewById(R.id.gift_description);
    }

    public void updatePrice(String p){
        txt.clear();
        txt.append(p).append(END_STR);
        txt.setSpan(mSpan,p.length()+1,txt.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        price.setText(txt);
    }

    public Gift getGift() {
        return gift;
    }

    public void setGift(Gift gift) {
        this.gift = gift;
        if(this.gift.isSelected()){
            mItemView.setSelected(true);
        }else{
            mItemView.setSelected(false);
        }
    }
}
